// $codepro.audit.disable fieldJavadoc, numericLiterals, variableShouldBeFinal
/* Copyright (c) 2011 Team A CS2340. All rights reserved.*/

package edu.gatech.teama.doctorsoffice.client.view;

import javax.swing.JPanel;

import edu.gatech.teama.doctorsoffice.client.presenter.AddUserPresenter;
import edu.gatech.teama.doctorsoffice.client.presenter.ServerConnection;
import edu.gatech.teama.doctorsoffice.model.SystemAdmin;

import net.miginfocom.swing.MigLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextField;

import javax.swing.JPasswordField;

/**
 * AddUserPanel.java
 * @author unknown
 * @version 1.0
 */
public class AddUserPanel extends JPanel {

	private AddUserPresenter myPresenter;

	private JComboBox typeBox;

	private JTextField firstNameField;

	private JTextField lastNameField;

	private JComboBox genderBox;

	private JTextField phoneField;

	private JTextField emailField;

	private JTextField addressField;

	private JTextField cityField;

	private JTextField zipField;

	private JTextField usernameField;

	private JPasswordField passwordField;

	private JComboBox stateBox;

	/**
	 * Create the panel.
	 */
	public AddUserPanel() { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods
		setLayout(new MigLayout("", "[][][grow]", "[][][][][][][][][][][][][][][]"));

		JLabel lblNewUser = new JLabel("New User:");
		lblNewUser.setFont(new Font("Tahoma", Font.PLAIN, 16));
		add(lblNewUser, "cell 0 0");

		JLabel lblType = new JLabel("Type:");
		add(lblType, "cell 1 1,alignx trailing");

		typeBox = new JComboBox();
		typeBox.setModel(new DefaultComboBoxModel(
				new String[] {"Patient", "Doctor", "Nurse", "SystemAdmin"}));
		if (!(ServerConnection.getInstance().getLoggedInUser() instanceof SystemAdmin)){
			typeBox.setEnabled(false);
		}
		add(typeBox, "cell 2 1,growx");

		JLabel lblUsername = new JLabel("Username:");
		add(lblUsername, "cell 1 2,alignx trailing");

		usernameField = new JTextField();
		add(usernameField, "cell 2 2,growx");
		usernameField.setColumns(10);

		JLabel lblPassword = new JLabel("Password:");
		add(lblPassword, "cell 1 3,alignx trailing");

		passwordField = new JPasswordField();
		add(passwordField, "cell 2 3,growx");

		JLabel lblFirstName = new JLabel("First Name:");
		add(lblFirstName, "cell 1 4,alignx trailing");

		firstNameField = new JTextField();
		add(firstNameField, "cell 2 4,growx");
		firstNameField.setColumns(10);

		JLabel lblLastName = new JLabel("Last Name:");
		add(lblLastName, "cell 1 5,alignx trailing");

		lastNameField = new JTextField();
		add(lastNameField, "cell 2 5,growx");
		lastNameField.setColumns(10);

		JLabel lblGender = new JLabel("Gender:");
		add(lblGender, "cell 1 6,alignx trailing");

		genderBox = new JComboBox();
		genderBox.setModel(new DefaultComboBoxModel(new String[] {"Male", "Female"}));
		add(genderBox, "cell 2 6,growx");

		JLabel lblPhoneNumber = new JLabel("Phone Number:");
		add(lblPhoneNumber, "cell 1 7,alignx trailing");

		phoneField = new JTextField();
		add(phoneField, "cell 2 7,growx");
		phoneField.setColumns(10);

		JLabel lblEmailAddress = new JLabel("E-mail Address:");
		add(lblEmailAddress, "cell 1 8,alignx trailing");

		emailField = new JTextField();
		add(emailField, "cell 2 8,growx");
		emailField.setColumns(10);

		JLabel lblAddress = new JLabel("Address:");
		add(lblAddress, "cell 1 9,alignx trailing");

		addressField = new JTextField();
		add(addressField, "cell 2 9,growx");
		addressField.setColumns(10);

		JLabel lblCity = new JLabel("City:");
		add(lblCity, "cell 1 10,alignx trailing");

		cityField = new JTextField();
		add(cityField, "cell 2 10,growx");
		cityField.setColumns(10);

		JLabel lblZipCode = new JLabel("ZIP Code:");
		add(lblZipCode, "cell 1 11,alignx trailing");

		zipField = new JTextField();
		add(zipField, "cell 2 11,growx");
		zipField.setColumns(10);

		JLabel lblState = new JLabel("State:");
		add(lblState, "cell 1 12,alignx trailing");

		stateBox = new JComboBox();
		stateBox.setEditable(true);
		add(stateBox, "cell 2 12,growx");
		myPresenter = new AddUserPresenter();
	}

	/**
	 * ok pressed
	 */
	public void okPressed() {
		myPresenter.addUser((String) typeBox.getSelectedItem(), usernameField.getText(),
				new String(passwordField.getPassword()),
				firstNameField.getText(), lastNameField.getText(),
				(String) genderBox.getSelectedItem(), 
				phoneField.getText(), emailField.getText(),
				addressField.getText(), cityField.getText(), 
				zipField.getText(), (String) stateBox.getSelectedItem());
	}

}
